package com.le.tester.book.effectivejava3rdchinese.secondReading.l34;

/**
 * createTime：2024-09-13 13:58
 * description：使用enum实现基本运算,感觉这样子简洁易读
 */
public enum Operation {

    PLUS {
        //double会丢失精度
        public double apply(double x, double y) {
            return x + y;
        }
    },
    MINUS {
        public double apply(double x, double y) {
            return x - y;
        }
    };


    //enum中暴露的抽象方法
    public abstract double apply(double x, double y);

    public static void main(String[] args) {
        double apply = Operation.PLUS.apply(2.0, 2.0);
        System.out.println(apply);

    }
}
